﻿using System;
using System.Configuration;
using WebStickyNotes.Contracts;

namespace WebStickyNotes.Helpers
{
    public static class TaskStateHelper
    {
        public static TaskState GetState(TaskDetail task)
        {
            var currentState = TaskState.Okay;
            var taskDate = task.MilestoneDate;
            var checkDays = double.Parse(ConfigurationManager.AppSettings["DaysBeforeDueDateTaskGoesAmber"]);

            if (task.PercentageComplete < 100)
            {
                if (taskDate < DateTime.Today)
                {
                    currentState = TaskState.Error;
                }
                else if (taskDate < DateTime.Today.AddDays(checkDays))
                {
                    currentState = TaskState.Warning;
                }
            }
            return currentState;
        }
    }
}
